package view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;
import model.*;
import controller.*;

/*****************************************
 * instrPanel
 * 
 * Responsible for display instructions
 * 
 * May create multiple panels for each page, or swap backgrounds
 * 
 * @author Stephen Gregory, Jun Wang
 *
 */

public class instrPanel extends JPanel {

		private static final long serialVersionUID = -5035582131291476234L;
		BufferedImage[] bkgd = new BufferedImage[3];
		BufferedImage currentBkgd;
		Font gameFont;
		JButton retButton = new JButton("Return to Main Menu");
		JButton nextButton = new JButton("Next");
		int bkgdIndex = 0;

		public instrPanel() {
			setLayout(null);
			setPreferredSize(new Dimension(1000, 600));	
			currentBkgd = null;	
			gameFont = new Font(Font.SANS_SERIF, Font.BOLD, 14);
			try {
				bkgd[0] = ImageIO.read(new File("instr_pg1.jpg"));
				bkgd[1] = ImageIO.read(new File("instr_pg2.jpg"));
				bkgd[2] = ImageIO.read(new File("instr_pg3.jpg"));
			} catch (IOException e) {}
			currentBkgd = bkgd[bkgdIndex];
	        
			retButton.setBounds(780, 470, 160, 30); 
			nextButton.setBounds(780, 470, 160, 30); 
	        add(nextButton);
	        
		}
		
	    public void paintComponent(Graphics g) {
	    	super.paintComponent(g);
			g.drawImage(currentBkgd, 0, 0, null);
	    }
	    
		@Override
		public boolean isFocusTraversable() {
		  return true;
		}

		public void addInstrReturnListener(ActionListener a) {
	        retButton.addActionListener(a);
	    }
		
		public void addNextListener(ActionListener a) {
	        nextButton.addActionListener(a);
	    }
		
		private void changeButton() {
			remove(nextButton);
			add(retButton);
	    }
		
		public void resetButtons() {
			remove(retButton);
			add(nextButton);
			bkgdIndex = 0;
			currentBkgd = bkgd[bkgdIndex];
	    }

		public void switchBkgd() {
			if (bkgdIndex != bkgd.length-2)
				currentBkgd = bkgd[++bkgdIndex];
			else {
				currentBkgd = bkgd[++bkgdIndex];
				changeButton();
			}
			repaint();			
		}

}